﻿Imports System.Data.SqlClient
Public Class clsMODULOS_ABIERTOS
    Private mstrFormulario As String
    Public Sub New()
        mstrFormulario = ""
    End Sub
    Public Sub CierraFormulario(ByVal frm As String)
        Call SetSqlCitra("DELETE FROM MODULOS_ABIERTOS WHERE NOMBREFORMULARIO='" & frm & "' AND USUARIO='" & UsuarioActivo & "'")
    End Sub
    Public Sub CierraFormularioAbiertos()
        Call SetSqlCitra("DELETE FROM MODULOS_ABIERTOS WHERE USUARIO='" & UsuarioActivo & "'")
    End Sub
    Public Sub AbreFormulario(ByVal frm As String)
        Dim sql As String = "Insert Into MODULOS_ABIERTOS (" & _
                            "NOMBREFORMULARIO," & _
                            "USUARIO)" & _
                            "VALUES (" & _
                            "@NOMBREFORMULARIO," & _
                            "@USUARIO)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("NOMBREFORMULARIO", frm)
        Command.Parameters.AddWithValue("USUARIO", UsuarioActivo)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
            If RowsAffected > 0 Then
                cnConn.Close()
            Else
                If cnConn.State = ConnectionState.Open Then
                    cnConn.Close()
                End If
            End If
        Catch ex As Exception
            'MsgBox(ex.Message, Global.Citra.Herramientas.TiposMensaje.Información, "Aviso")
        End Try
    End Sub
    Public Function EstatusFormulario(ByVal frm As String) As String
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim strSql As String
        Dim cmdBuscar As New SqlCommand
        Dim rdBuscar As SqlDataReader

        strSql = "SELECT USUARIO FROM MODULOS_ABIERTOS WHERE NOMBREFORMULARIO='" & frm & "'"

        cnConn.Open()
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = strSql

        rdBuscar = cmdBuscar.ExecuteReader

        Dim Usuarios As String = ""

        Do While rdBuscar.Read()
            Usuarios = Usuarios & "," & rdBuscar("USUARIO")
        Loop

        Usuarios = Mid(Usuarios, 2)
        Return Usuarios
        cnConn.Close()

    End Function

End Class
